<?php
function ls($dir, $exclude=array(".", ".."), $exact=true) {
		$liste=array();

		if ($handle = opendir($dir)) {
			while (false !== ($file = readdir($handle))) {
				$found=false;
		        foreach ($exclude as $pattern) {
			        if ( $exact ) {
			        	if ($pattern == $file) {
							$found=true;
			        		break;
			        	} 
			        } else {
			        	if (!(strpos($file, $pattern)===false)) {
			        		$found=true;
			        		break;
			        	}
			        }
			    }
	   			if (!$found) array_push($liste, $file) ;	
	   		}
    		closedir($handle);
    	}
    	return $liste;
}

 function listFiles($name) {

  if (is_file($name)) return array($name);
  $ret=array();
  if ($dir = opendir($name)) {

    while($file = readdir($dir)) {
      	if( is_file($name."/".$file) ) {
			array_push($ret, $name."/".$file);
      }
    }
    closedir($dir );
  }	
  return $ret;
}

function appendContent( $file, $content) {
		if (!$handle = fopen($file, 'a')) {
			echo "Cannot open file ($file)";
			return 1;
		}

		// Write $somecontent to our opened file.
		if (fwrite($handle, $content) === FALSE) {
			echo "Cannot write to file ($file)";
			return 1;
		}

		fclose($handle);
		return 0;
}
?>
